<?php
/**
 * Created by PhpStorm.
 * User: aron
 * Date: 2019/5/8
 * Time: 8:03 PM
 */

include_once "Rect.class.php";
include_once "Circle.class.php";

class Result
{
    private $shape;

    public function __construct($shape = "rect")
    {
        if (empty($shape)) {
            $this->shape = "rect";
        } else {
            $this->shape = $shape;
        }
    }

    public function __toString()
    {
        if ($this->shape == "rect") {
            return $this->generateRectResult();
        } else if ($this->shape == "circle") {
            return $this->generateCircleResult();
        }
        return "暂不支持";
    }

    private function generateRectResult()
    {
        $width = $_GET["width"];
        $height = $_GET["height"];
        $rect = new Rect($width, $height);
        $resultString = "计算结果：<br/>\r\n";
        $resultString .= "{$rect->getName()} 的周长是： {$rect->perimeter()}<br/>\r\n";
        $resultString .= "{$rect->getName()} 的面积是： {$rect->area()}<br/>\r\n";
        return $resultString;
    }

    private function generateCircleResult()
    {
        $radius = $_GET["radius"];
        $shape = new Circle($radius);
        $resultString = "计算结果：<br/>\r\n";
        $resultString .= "{$shape->getName()} 的周长是： {$shape->perimeter()}<br/>\r\n";
        $resultString .= "{$shape->getName()} 的面积是： {$shape->area()}<br/>\r\n";
        return $resultString;
    }

}